#include<iostream>
#include<algorithm>
// zdl:: 使用克鲁斯卡尔算法
using namespace std;
const int N = 2e3 + 10, M = (N - 1) * N / 2;
struct path
{
    int u, v, w;
}e[M];
int px[N], py[N];
int n, c;
int fa[N];
int find(int x){return x == fa[x] ? x : fa[x] = find(fa[x]);}
void un(int x, int y) { fa[find(x)] = find(y);}

int calc(int i, int j)
{
    return (px[i] - px[j]) * (px[i] - px[j]) + (py[i] - py[j]) * (py[i] - py[j]);
}
int main()
{
    cin >> n >> c;
    for (int i = 1; i <= n; i++)
    {
        cin >> px[i] >> py[i];
    }
    // 建图
    int cnt = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            int t = calc(i, j);
            if (t < c) 
            {
                continue;
            }
            e[cnt++] = {i, j, t};
        }
    }
    // 按照权值排序
    sort(e + 1, e + cnt, [](path& x, path& y){
        return x.w < y.w;
    });
    // 需要借用并查集
    for (int i = 1; i <= n; i++) fa[i] = i;

    int ret = 0, m = 0;
    
    for (int i = 1; i < cnt; i++)
    {
        int u = e[i].u, v = e[i].v, w = e[i].w;
        if (find(u) == find(v)) continue;

        m++;
        ret += w;
        un(u, v);
        // 没亮点都能连通，指的是最小生成树！ 不是梁丽娜给相连！！！
        if (m == n - 1) break;
    }

    if (m != n - 1) cout << -1 << endl;
    else cout << ret << endl;

    return 0;
}